package com.atguigu.gmall.order.rest;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.cart.CartFeignClient;
import com.atguigu.gmall.order.biz.OrderBizService;
import com.atguigu.gmall.order.vo.OrderSubmitVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:lyd
 * @Date:2023/9/5 0:20
 * @Version:1.0
 * @Description
 **/
@RestController
@RequestMapping("/api/order/auth")
public class OrderRestController {

    @Autowired
    OrderBizService orderBizService;

    @Autowired
    CartFeignClient cartFeignClient;

    /**
     * 下单
     * @param tradeNo
     * @param orderSubmitVo
     * @return
     */
    @PostMapping("/submitOrder")
    public Result submitOrder(@RequestParam("tradeNo") String tradeNo,
                              @RequestBody OrderSubmitVo orderSubmitVo) {
        //1、下单
        Long orderId = orderBizService.submitOrder(tradeNo, orderSubmitVo);

        //2、删除下单后购物车选中的商品
        cartFeignClient.deleteChecked();
        return Result.ok(orderId.toString());//返回订单id，前端会自动带着订单id去支付页面
    }
}
